﻿@model BlogPostModel

@using Telerik.Web.Mvc.UI;
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)
@Html.Telerik().TabStrip().Name("blog-post-edit").Items(x =>
{
    x.Add().Text(T("Admin.ContentManagement.Blog.BlogPosts.Info").Text).Content(TabInfo().ToHtmlString()).Selected(true);
    x.Add().Text(T("Admin.Common.SEO").Text).Content(TabSeo().ToHtmlString());
    x.Add().Text(T("Admin.ContentManagement.News.NewsItems.Sites").Text).Content(TabSites().ToHtmlString());

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "category-edit"));
})

@helper TabInfo()
{
    
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.LanguageId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.LanguageId, new SelectList(ViewBag.AllLanguages, "Id", "Name"))
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.Title):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Title)
                @Html.ValidationMessageFor(model => model.Title)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.Body):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.Body, "RichEditor")
                @Html.ValidationMessageFor(model => model.Body)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.AllowComments):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AllowComments)
                @Html.ValidationMessageFor(model => model.AllowComments)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.Tags):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Tags)
                @Html.ValidationMessageFor(model => model.Tags)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.StartDate):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.StartDate)
                @Html.ValidationMessageFor(model => model.StartDate)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.EndDate):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.EndDate)
                @Html.ValidationMessageFor(model => model.EndDate)
            </td>
        </tr>
    </table>
}
@helper TabSeo()
{
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.MetaKeywords):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaKeywords)
                @Html.ValidationMessageFor(model => model.MetaKeywords)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.MetaDescription):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaDescription)
                @Html.ValidationMessageFor(model => model.MetaDescription)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.MetaTitle):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaTitle)
                @Html.ValidationMessageFor(model => model.MetaTitle)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.SeName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.SeName)
                @Html.ValidationMessageFor(model => model.SeName)
            </td>
        </tr>
    </table>
}

@helper TabSites()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToSites)").click(toggleSiteMapping);

            toggleSiteMapping();
        });


        function toggleSiteMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToSites)').is(':checked')) {
                $('#pnl-available-sites').show();
            }
            else {
                $('#pnl-available-sites').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.LimitedToSites):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToSites)
                @Html.ValidationMessageFor(model => model.LimitedToSites)
            </td>
        </tr>
        <tr id="pnl-available-sites">
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.AvailableSites):
            </td>
            <td class="adminData">
                @if (Model.AvailableSites != null && Model.AvailableSites.Count > 0)
                {
                    foreach (var site in Model.AvailableSites)
                    {
                    <div>
                        <input type="checkbox" name="SelectedSiteIds" value="@site.Id" checked="@(Model.SelectedSiteIds != null && Model.SelectedSiteIds.Contains(site.Id))" />@site.Name
                    </div>
                    }
                }
                else
                {
                    <div>No sites defined</div>
                }</td>
        </tr>
    </table>
}

